package com.richfit.barcodesystem_cczt.utils.sharedPreferences;


import com.richfit.barcodesystem_cczt.activitis.model.base.BaseBO;

public class DatabaseHelper {
    /**
     * 登录账号
     */
    public static String ACCOUNT = "login_account";
    /**
     * 登录密码
     */
    public static String PASSWORD = "login_password";
    /**
     * 登录token
     */
    public static String TOKEN = "login_cookie";

    /**
     * 获得基本信息
     *
     * @return
     */
    public static BaseBO getBaseBO() {
        BaseBO ret = new BaseBO();
        ret.accounts = SharedPreferencesHelper.get("accounts", ret.accounts);
        ret.account = SharedPreferencesHelper.get(ACCOUNT, ret.account);
        ret.password = SharedPreferencesHelper.get(PASSWORD, ret.password);
        ret.remembered = SharedPreferencesHelper.get("remembered", ret.remembered);
        ret.requestUrl = SharedPreferencesHelper.get("requestUrl", ret.requestUrl);
        ret.cookie = SharedPreferencesHelper.get(TOKEN, ret.cookie);
        ret.username = SharedPreferencesHelper.get("username", ret.username);

        return ret;
    }

    public static String getSp(String key, String defaultValue) {
        return SharedPreferencesHelper.get(key, defaultValue);
    }

    /**
     * 保存基本信息
     *
     * @param
     * @return
     * @throws Exception
     */
    public static boolean updateBo(BaseBO bo) {
        SharedPreferencesHelper.put("accounts", bo.accounts);
        SharedPreferencesHelper.put(ACCOUNT, bo.account);
        SharedPreferencesHelper.put(PASSWORD, bo.password);
        SharedPreferencesHelper.put("remembered", bo.remembered);
        SharedPreferencesHelper.put("requestUrl", bo.requestUrl);
        SharedPreferencesHelper.put(TOKEN, bo.cookie);
        SharedPreferencesHelper.put("username", bo.username);
        return true;
    }

    public static boolean editSp(String key, String value) {
        SharedPreferencesHelper.put(key, value);

        return true;
    }

}
